<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "job".
 *
 * @property int         $id
 * @property int         $uid 发布者
 * @property int         $type 类型
 * @property int         $status 支付状态
 * @property int         $forbidden 是否屏蔽
 * @property int         $pay_needed 需要支付
 * @property string      $title 招聘名称
 * @property int         $created_at 创建时间
 * @property int         $updated_at 最后更新时间
 * @property string      $content 兼职详情
 * @property string      $contact_name 联系人姓名
 * @property string      $contact_phone 联系人电话
 * @property int         $hide 发布状态（用户控制）
 * @property int         $view_num 报名查看人数
 *
 * @property User        $u
 * @property JobInfo[]   $jobInfos
 * @property JobInfo     $jobInfo
 * @property JobRecord[] $jobRecords
 * @property Order       $order
 */
class Job extends \yii\db\ActiveRecord
{
    const PARTTIME_TYPE = 1;
    const MISSION_TYPE = 2;

    const PAY_STATUS = 1;
    const NOT_PAY_STATUS = 0;

    const PAY_NEEDED = 1;
    const PAY_NOT_NEEDED = 0;
    //hide用
    const FORBIDDEN = 20;
    const ACCESS = 10;

    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'job';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['uid', 'type'], 'required'],
            [['uid', 'type', 'status', 'forbidden', 'pay_needed', 'created_at', 'updated_at', 'view_num'], 'integer'],
            [['content'], 'string'],
            [['title', 'contact_name', 'contact_phone'], 'string', 'max' => 255],
            [
                ['uid'],
                'exist',
                'skipOnError'     => true,
                'targetClass'     => User::className(),
                'targetAttribute' => ['uid' => 'id']
            ],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id'            => 'ID',
            'uid'           => '发布者',
            'type'          => '类型',
            'status'        => '状态',
            'forbidden'     => '是否屏蔽',
            'pay_needed'    => '需要支付',
            'title'         => '招聘名称',
            'created_at'    => '创建时间',
            'updated_at'    => '最后更新时间',
            'content'       => '兼职详情',
            'contact_name'  => '联系人姓名',
            'contact_phone' => '联系人电话',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getU()
    {
        return $this->hasOne(User::className(), ['id' => 'uid']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getJobInfos()
    {
        return $this->hasMany(JobInfo::className(), ['jid' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getJobInfo()
    {
        return $this->hasOne(JobInfo::className(), ['jid' => 'id']);
    }


    /**
     * @return \yii\db\ActiveQuery
     */
    public function getJobRecords()
    {
        return $this->hasMany(JobRecord::className(), ['jid' => 'id']);
    }


    public function getOrder()
    {
        return $this->hasOne(Order::className(), ['job_id' => 'id']);
    }

}
